package com.tenebrous.jestic.service.framwork.meber.author;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tenebrous.jestic.entity.framwork.meber.author.AuthRouter;
import com.tenebrous.jestic.mapper.idao.framwork.meber.author.AuthRouterMapper;
import com.tenebrous.jestic.service.SuperService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AuthRouterService extends SuperService<AuthRouter> {

    @Autowired
    private AuthRouterMapper mapper;

    @Override
    @Autowired
    protected void setSuperMapper() {

        super.setSuperMapper(this.mapper);
    }

    public PageInfo<AuthRouter> queryPagingList( Integer pageIndex, Integer pageSize, String name, String path ) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> this.mapper.selectByCondition(name, path));
    }

    @Transactional
    public int deleteByIds( String[] ids ) {
        int i = 0;
        for (String id : ids) {
            if(StringUtils.isNotBlank(id)) {
                i += this.mapper.deleteByPrimaryKey(id);
            }
        }
        return i;
    }
}
